/*

Original Formula

FM:=MOV(C,3,E)-MOV(C,10,E);
SM:=MOV(C,4,E)-MOV(C,18,E);
HLTu:=FM>0 AND SM>0;
{ -this will paint the candles blue}
HLTd:=FM<0 AND SM<0;
{ -this will paint the candles red (set candle color to yellow, so you get yellow neutral bars)}
PLRosc:=MOV(TP(),4,S)-MOV(TP(),32,S);
PLRu:= CROSS(PLRosc,0);
{ - This plots the large black up arrows}
PLRd:= CROSS(0,PLRosc);
{ - This plots the large black down arrows}
WBP:=(HHV(HIGH,5)+LLV(LOW,5)+CLOSE)/3;
WV:=SUM(VOLUME,5);
VFORCE:= SUM(((TP()-REF(TP(),-1))/REF(TP(),-1))*VOLUME,13)/SUM(VOLUME,13);
VFORCEup:=IF(PLRu OR PLRd,0,VFORCE);
{ - if plr is true, we only want a large arrow on the bar}
VFORCEdn:=IF(PLRd OR PLRu,0,VFORCE);
{ - if plr is true, we only want a large arrow on the canlde}
FORCEu:=VFORCEup>0;
{ - plots a blue arrow on candles}
FORCEd:=VFORCEdn<0;
{ -plots a red arrow on candles}

{CROWD BIAS  }
N:=16;
POBC1:=(HHV(CLOSE,N)+LLV(CLOSE,N))/2;
POBC2:=(HHV(POBC1,N)+LLV(POBC1,N))/2;
POBC3:=(HHV(POBC2,N)+LLV(POBC2,N))/2;
POBC4:=(HHV(POBC3,N)+LLV(POBC3,N))/2;
POBC5:=(HHV(POBC4,N)+LLV(POBC4,N))/2;
POBC6:=(HHV(POBC5,N)+LLV(POBC5,N))/2;
POBC7:=(HHV(POBC6,N)+LLV(POBC6,N))/2;
POBC8:=(HHV(POBC7,N)+LLV(POBC7,N))/2;
POBC9:=(HHV(POBC8,N)+LLV(POBC8,N))/2;
POBC10:=(HHV(POBC9,N)+LLV(POBC9,N))/2;
AV:= (POBC1+POBC2+POBC3+POBC4+POBC5+POBC6+POBC7+POBC8+POBC9+POBC10)/10;
CBOsc:=100*((CLOSE-AV)/(HHV(CLOSE,10)-LLV(CLOSE,10)));

UpTrend:=CBOsc>0;
{ -plots the blue line and ribbon (use trend in vt)}
DownTrend:=CBOsc<0;
{ -plots the red line and ribbon (use trend in vt)}
Neutral:=CBOsc=0;

*/


#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 Yellow
#property indicator_maximum 1
#property indicator_minimum 0
//---- input parameters


//---- buffers  WHH=HHV(WH,25);WLL=LLV(WL,25);WBP_MA=MOV(WBP,25,S)
double HLTu[];
double HLTd[];
double HLTn[];




//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- 3 additional buffers are used for counting.
   IndicatorBuffers(3);
//---- name for DataWindow and indicator subwindow label


//----
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,5);
   SetIndexBuffer(0, HLTu);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,5);
   SetIndexBuffer(1, HLTd);
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,5);
   SetIndexBuffer(2, HLTn);
   short_name="KP Bar color";
   IndicatorShortName(short_name);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| KP Bar color                                     |
//+------------------------------------------------------------------+
int start()
  {
   int    i,k,counted_bars=IndicatorCounted();
   
   if(Bars<=20) return(0);
//---- initial zero

//---- last counted bar will be recounted
   int limit=Bars-counted_bars;
   if(counted_bars>0) limit++; 

/*---- FM:=MOV(C,3,E)-MOV(C,10,E);
SM:=MOV(C,4,E)-MOV(C,18,E);
HLTu:=FM>0 AND SM>0;
{ -this will paint the candles blue}
HLTd:=FM<0 AND SM<0;
{ -this will paint the candles red*/
   double FM,SM;
   for(i=0; i<limit; i++)
     { FM=iMA(NULL,0,3,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,i);
      SM=iMA(NULL,0,4,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,18,0,MODE_EMA,PRICE_CLOSE,i);
      if (FM>0 && SM>0) {HLTu[i]=1;HLTd[i]=0;HLTn[i]=0;}
      else if (FM<0 && SM<0) {HLTu[i]=0;HLTd[i]=1;HLTn[i]=0;}
           else {HLTu[i]=0;HLTd[i]=0;HLTn[i]=1;}
     }


   return(0);
  }
//+------------------------------------------------------------------+